<jsp:useBean id="user" class="Domain.UserBean" scope="page"/>
<jsp:setProperty name="user" property="*"/>

<%@ page import = "Domain.*" %>
 
<!DOCTYPE html>
<html>
    <head>
        <title>Register</title>
        <link rel="stylesheet" type="text/css" href="stylesheets/general.css" />
    </head>
    <body>
        <div class ="header">
            <h1 id="margin">Register</h1>
        </div>
        <div class="main" id="margin">
        <form method="POST" action="register.jsp">
            Name: <input type="text" name="userName" size="50"><br/>
            Password: <input type="password"  name="password" size="50"><br/>
            <input type="submit" value="Register">
            
            <jsp:useBean id="currentUser" scope="session" class="Domain.UserBean" />
            <% 
                Website web = Website.getInstance();
                if(user.getuserName() != null && !web.userExists(user.getuserName())){
                    currentUser.copy(user);
                    int userID = web.getUserID(currentUser.getuserName());
                    currentUser.setuserId(userID);
                    web.addNewUser(user);
                    response.sendRedirect("blogview.jsp");
                }
            %>
        </form>
        </div>
    </body>
</html>
